package com.twotiger.and.activity.project;

import java.util.ArrayList;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import app.twotiger.p2p.R;

import com.alibaba.fastjson.JSON;
import com.twotiger.and.activity.base.BaseActivity;
import com.twotiger.and.adapter.SelectCouponAdapter;
import com.twotiger.and.bean.Coupon;
import com.twotiger.and.bean.InverstCoupon;
import com.twotiger.and.util.ViewUtils;

public class SelectCouponPage extends BaseActivity {

    private Button cancel_btn;
    private ListView selectcoupon_list;
    private ImageView sub_title_left_bt;
    private TextView sub_title_center_tv;

    @Override
    protected View loadViewLayout(LayoutInflater inflater) {
        View view = inflater.inflate(R.layout.choice_coupon_layout, null);
        return view;
    }
    
    @Override
    protected void processLogic() {
        sub_title_center_tv.setText("选择优惠券");
        sub_title_left_bt.setVisibility(View.VISIBLE);
        InverstCoupon inverstCoupon = JSON.parseObject(application.getInverstcouponjson(),
            InverstCoupon.class);
        ArrayList<Coupon> coupon_canlist = (ArrayList<Coupon>) JSON.parseArray(
            inverstCoupon.getKyList(), Coupon.class);
        ArrayList<Coupon> coupon_cantlist = (ArrayList<Coupon>) JSON.parseArray(
            inverstCoupon.getBkyList(), Coupon.class);
        selectcoupon_list.setAdapter(new SelectCouponAdapter(mContext, coupon_canlist,
            coupon_cantlist));
    }

    @Override
    protected void setListener() {
        cancel_btn.setOnClickListener(this);
        sub_title_left_bt.setOnClickListener(this);
    }

    @Override
    protected void findViewById(View view) {
        cancel_btn = (Button) view.findViewById(R.id.cancel_btn);
        selectcoupon_list = (ListView) view.findViewById(R.id.selectcoupon_list);
        sub_title_left_bt = (ImageView) view.findViewById(R.id.sub_title_left_bt);
        sub_title_center_tv = (TextView) view.findViewById(R.id.sub_title_center_tv);
    }

    @Override
    protected void onBackPress() {
        finish();
        overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
        case R.id.cancel_btn:
            if (ViewUtils.isFastDoubleClick(view)) {
                return;
            }
            setResult(InverstInputAmountPage.COUPONRESULT_CANCELED);
        case R.id.sub_title_left_bt:
            onBackPress();
            break;
        default:
            break;
        }
    }

}
